#!/bin/bash
path=$(readlink -f "$(dirname "$0")")
cd $path
my_array=("etm" "ebusiness") #其他服务由tm来启动

# 记录重启日志
reLog="$path/../restart.log"
if [ ! -f "$reLog" ]; then
   touch $reLog
fi

data_time=`date "+%Y-%m-%d %H:%M:%S"`

for value in ${my_array[@]}
do
  if [ ! $(ps -ef | grep  -w ${value} | grep -v grep | awk '{print $2}'|wc -l) -gt 0 ]; then
    nohup ./${value} > /dev/null 2>&1 &
    echo -e "$data_time restart $value" >> ${reLog}
    echo "${value} 启动成功"
  fi
done

if [ $(ps -ef | grep  -w etunnel | grep -v grep | awk '{print $2}'|wc -l) -gt 0 ];
  then echo "etunnel ok"
  else
    nohup ./etunnel -ip 42.192.199.243 -port 39999 -id self > /dev/null 2>&1 &
	echo run etunnel
fi

if [ ! $(ps -ef | grep  -w appServer | grep -v grep | awk '{print $2}'|wc -l) -gt 0 ]; then
  ../mediaserver/run.sh
  echo -e "$data_time restart appServer" >> ${reLog}
fi
source ./rollback.sh